module.exports = function ($scope, $resource, $modal, toaster, deleteStr) {
	
	$scope.currentPage = 1;			//当前页码
	$scope.itemsPerPage = 10;		//每页显示几条

	//查询
	$scope.getDate = function(pageNo){
		$scope.loading = true;
		var para = {
			'pageNo': pageNo,
			'pageSize': $scope.itemsPerPage
		}
		$resource('/api/as/atc/sale/getSaleList', {}, {}).save(para, function(res){
            if (res.errcode === 0) {
				$scope.saleList = res.data.results;
				$scope.totalItems = res.data.totalRecord;
				$scope.currentPage = pageNo;
				$scope.loading = false;
            } else {
                toaster.error({title: '', body: '查询信息失败'});
            }
        });
	}
	$scope.getDate(1);

	//添加招徕产品
	$scope.add = function() {
		var modalInstance = $modal.open({
			template: require('../views/productSetting.html'),
			controller: 'productSetting',
			size: 'lg',
			resolve: {
				saleCodes: function () {
					return $scope.saleList;
				}
			}
		});
		//关闭模态框刷新页面
		modalInstance.result.then(function(result) {
			$scope.getDate(1);
		});
	}

	//删除产品
	$scope.delete = function(code) {
		if(confirm('删除后此产品申报的旅游团将不再获取招徕奖励！\r\n 确认删除此产品吗？')){
			$resource('/api/as/atc/sale/deleteSale', {}, {}).save({'sale_code': code}, function(res){
				if (res.errcode === 0) {
					$scope.getDate($scope.currentPage);
					toaster.success({title: '', body: '删除成功'});
				} else {
					toaster.error({title: '', body: '删除失败'});
				}
			});
		}
	}

};